import { CydonElement } from 'cydon'
import { Permissons } from '../api'

const keys = Object.keys(Permissons)

/** 编辑权限对话框 */
export class EditPerm extends CydonElement {
	roles = keys.filter((x: any) => !+x || (x & (x - 1)) != 0)
	perms = keys.filter((x: any) => +x && (x & (x - 1)) == 0)
	names = Permissons
	value = 0
	perm!: number
	res = this

	get hasPerm() {
		return (this.value & this.perm) != 0
	}
	set hasPerm(_: boolean) {
		// HACK
		this.value = this.res.value ^= this.perm
	}
}
customElements.define('edit-perm', EditPerm)

declare global {
	interface HTMLElementTagNameMap {
		'edit-perm': EditPerm
	}
}
